//
//  SISSUploadSuccessViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/4.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSUploadSuccessViewController.h"
#import "SISSHouseProgressViewController.h"

@interface SISSUploadSuccessViewController ()


@property (weak, nonatomic) UIImageView *imageView;
@property (weak, nonatomic) UILabel *tipLabel;
@property (weak, nonatomic) UIButton *backProgressButton;

@end

@implementation SISSUploadSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = self.title ? self.title : @"上传成功";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backProgressButtonClickAction)];
}



- (void)setTipStr:(NSString *)tipStr {
    _tipStr = tipStr;
    self.tipLabel.text = tipStr;
}

- (void)setPopBackClassType:(SISSProgressPopBackClassType)popBackClassType {
    _popBackClassType = popBackClassType;
    switch (popBackClassType) {
        case SISSProgressPopBackClassTypeHouse:
            self.popBackClassName = @"SISSHouseProgressViewController";
            break;
        case SISSProgressPopBackClassTypePassenger:
            self.popBackClassName = @"SISSPassengerProgressViewController";
            break;
        case SISSProgressPopBackClassTypeRentOut:
            self.popBackClassName = @"SISSRentOutProgressViewController";
            break;
        case SISSProgressPopBackClassTypeTenant:
            self.popBackClassName = @"SISSTenantProgressViewController";
            break;
        case SISSProgressPopBackClassTypeHouseCooperation:
            self.popBackClassName = @"SISSHouseCooperationProgressViewController";
            break;
        case SISSProgressPopBackClassTypePassengerCooperation:
            self.popBackClassName = @"SISSPassengerCooperationProgressViewController";
            break;
            
        default:
            break;
    }
}

- (void)backProgressButtonClickAction {
    
    if (!self.popBackClassName || !NSClassFromString(self.popBackClassName)) return;
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:NSClassFromString(self.popBackClassName)]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"checkSelected"];
    [self.view addSubview:imageView];
    self.imageView = imageView;
    
    UILabel *tipLabel = [UILabel yyr_labelWithText:self.tipStr ? self.tipStr : @"已保存" fontSize:16 textColor:MAIN_TEXT_COLOR alignment:NSTextAlignmentCenter];
    tipLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.view addSubview:tipLabel];
    self.tipLabel = tipLabel;
    
    UIButton *backProgressButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backProgressButton setTitle:@"返回进度" forState:UIControlStateNormal];
    [backProgressButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backProgressButton setBackgroundColor:MAIN_COLOR];
    [backProgressButton addTarget:self action:@selector(backProgressButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    backProgressButton.layer.cornerRadius = 4;
    backProgressButton.layer.masksToBounds = YES;
    [self.view addSubview:backProgressButton];
    self.backProgressButton = backProgressButton;
    
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_topLayoutGuideBottom).offset(4 * globelMargin);
        make.centerX.equalTo(weakSelf.view);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH * 0.2, SCREEN_WIDTH * 0.2));
    }];
    
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imageView.mas_bottom).offset(2 * globelMargin);
        make.centerX.equalTo(weakSelf.imageView);
    }];
    
    [self.backProgressButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.tipLabel.mas_bottom).offset(globelMargin * globelMargin);
        make.centerX.equalTo(weakSelf.view);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH * 0.8, 44));
    }];
    
}

@end
